package com.aoyy.util.product;

import java.util.Map;
import org.apache.struts2.util.StrutsTypeConverter;
import com.aoyy.util.product.Sex;
/**====================================================================
 * <code>SexConverter</code> class is served as a sex converter
 * @author Administrator
 * @date 2017-07-12
 * =====================================================================  */
public class SexConverter extends StrutsTypeConverter{
  @SuppressWarnings("rawtypes")
  @Override
  public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
    Sex[] sexs = Sex.values();
    for (Sex sex: sexs) {
      if (sex.getName().equals(arg1[0])) {
    	return sex;  
      }
    }
	return null;
  }

  @Override
  public String convertToString(@SuppressWarnings("rawtypes") Map arg0, Object arg1) {
	return ((Sex)arg1).getName();
  }

}
